#include "QQRTCVideoEngineFactory.h"

QQRTCVideoEngine* QQRTCVideoEngineFactory::create(const VideoHandleType type, QObject* parent)
{
	switch (type) {
	case VideoHandleType::AGORA:
		return new QQRTCVideoEngineByAgora(parent);
	case VideoHandleType::WEBRTC:
		return nullptr;
	}
	return nullptr;
}

QQRTCVideoEngine* QQRTCVideoEngineFactory::create(const char* name, QObject* parent)
{
	Q_ASSERT(name);
	if (!name) {
		return nullptr;
	}
	if (qstricmp(name, "agora") == 0) {
		return new QQRTCVideoEngineByAgora(parent);
	}
	if (qstricmp(name, "webrtc") == 0) {
		return nullptr;
	}
	qWarning() << "Unsupported lottie backend:" << name;
	return nullptr;
}

QQRTCVideoEngine* QQRTCVideoEngineFactory::create(QObject* parent)
{
	const QString preferred = qEnvironmentVariable("AVCALL_PREFERRED_ENGINE", QStringLiteral("agora"));
	if (const auto engine = create(qUtf8Printable(preferred), parent)) {
		return engine;
	}
	if (const auto engine = create("webrtc", parent)) {
		return engine;
	}
	qWarning() << "rlottie is not available.";
	return nullptr;
}

